//
//  AccountAndSafeTableViewController.m
//  糗事百科
//
//  Created by 奚超明 on 16/6/7.
//  Copyright © 2016年 奚超明. All rights reserved.
//

#import "AccountAndSafeTableViewController.h"

@interface AccountAndSafeTableViewController ()
/** 图片数组 */
@property (nonatomic, strong) NSMutableArray *imageArr;
/** 标题数组 */
@property (nonatomic, strong) NSMutableArray *titleArr;

@end

@implementation AccountAndSafeTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 界面设置
    [self setupTableView];
}

#pragma mark - 设置界面
- (void)setupTableView
{
    // 标题
    self.navigationItem.title = @"密保设定";
    
    self.tableView = [[UITableView alloc] initWithFrame:self.tableView.frame style:UITableViewStyleGrouped];
    
    // 设置表尾
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 100)];
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, view.xcm_width - 20, 50)];
    label.text = @"绑定以上帐号可以帮助您找回密码或登录糗百，这些帐号仅做密保用途不会被展示透露";
    label.numberOfLines = 0;
    label.font = [UIFont systemFontOfSize:12];
    label.textColor = kRGBColor(118, 118, 136);
    [view addSubview:label];
    self.tableView.tableFooterView = view;
}

#pragma mark - 行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.imageArr.count;
}

#pragma mark - 返回cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AccountAndSafeTableViewCell"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"AccountAndSafeTableViewCell"];
    }
    
    // 确定现在的登录平台
    NSInteger platformType = [[[NSUserDefaults standardUserDefaults] objectForKey:@"platformType"] integerValue];
    NSLog(@"%zd", platformType);
    
    if (platformType == SSDKPlatformTypeQQ) {
        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
        UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    } else if (platformType == SSDKPlatformTypeWechat) {
        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1 inSection:0];
        UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    } else if (platformType == SSDKPlatformTypeSinaWeibo) {
        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:2 inSection:0];
        UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
    cell.textLabel.textColor = kRGBColor(118, 118, 136);
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.imageView.image = [UIImage imageNamed:self.imageArr[indexPath.row]];
    cell.textLabel.text = self.titleArr[indexPath.row];
    return cell;
}

#pragma mark - 懒加载
- (NSMutableArray *)imageArr
{
    if (!_imageArr) {
        _imageArr = [@[@"qq", @"weixin", @"weibo", @"email"] mutableCopy];
    }
    return _imageArr;
}

- (NSMutableArray *)titleArr
{
    if (!_titleArr) {
        _titleArr = [@[@"qzuser", @"微信", @"新浪微博", @"邮箱"] mutableCopy];
    }
    return _titleArr;
}
@end
